import Mock from 'mockjs'
import { builder, getBody } from '../util'

const username = ['all@admin.com', 'super']
const password = ['e10adc3949ba59abbe56e057f20f883e'] // admin, 123456

const login = (options) => {
  const body = getBody(options)
  if (!username.includes(body.username) || !password.includes(body.password)) {
    return builder({ isLogin: true }, '账户或密码错误', 0)
  }

  return builder({
    id: Mock.mock('@guid'),
    name: Mock.mock('@name'),
    username: 'all@admin.com',
    password: '',
    avatar: 'https://gw.alipayobjects.com/zos/rmsportal/jZUIxmJycoymBprLOUbT.png',
    status: 1,
    telephone: '',
    lastLoginIp: '27.154.74.117',
    lastLoginTime: 1534837621348,
    creatorId: 'admin',
    createTime: 1497160610259,
    deleted: 0,
    roleId: 'admin',
    lang: 'zh-CN',
    token: '7ad06ad9-7fb9-4dd0-bc57-e87c8eb645a4'
  }, '', 200, { 'Custom-Header': Mock.mock('@guid') })
}

const logout = () => {
  return builder({}, '[测试接口] 注销成功')
}

Mock.mock(/\/auth\/login/, 'post', login)
Mock.mock(/\/auth\/logout/, 'post', logout)
